<?php
namespace App\Common\Server\Api\Gateway;

use App\Common as com;
use App as nameApp;
use App\Common\Server\Api\Gateway\ApiRequest as nameApiRequest;
use App\Common\Server\Api as nameApi;

class ApiRequest extends nameApi\Base {

	/**
	 * timestamp超时时间(秒)
	 * @var int
	 */
	public static int $timestampTimeoutS = 300;

	/**
	 * 是否验证签名 @TODO :: 未做
	 * @var bool [false]不验证 [true][默认]验证
	 */
	// private bool $isVerifySign = true;

	/**
	 * token对象(调用时初始化，方法：$this->token())
	 * @var com\Cla\Com\Token
	 */
	private com\Cla\Com\Token $accessTokenObj;

	/**
	 * @var ApiRequest\ApiData
	 */
	private ApiRequest\ApiData $apiDataObj;

	/**
	 * 签名对象(调用时初始化，方法：$this->sign())
	 * @var ApiRequest\ApiSign
	 */
	private ApiRequest\ApiSign $signObj;

	/**
	 * 权限对象(调用时初始化，方法：$this->auth())
	 * @var ApiRequest\ApiAuth
	 */
	private ApiRequest\ApiAuth $authObj;

	/**
	 * 获取api响应对象
	 * @var ApiResponse
	 */
	private ApiResponse $apiResponse;

	/**
	 * 获取apiData对象
	 * @return ApiRequest\ApiData apiData对象
	 */
	public function apiData():ApiRequest\ApiData {
		if( ! isset( $this->apiDataObj ) ){
			$this->apiDataObj = ApiRequest\ApiData::make();
		}
		return $this->apiDataObj;
	}

	/**
	 * 获取token对象
	 * @return com\Cla\Com\Token token对象
	 */
	public function accessToken():com\Cla\Com\Token {
		if( ! isset( $this->accessTokenObj ) ){
			$this->accessTokenObj = new com\Cla\Com\Token( $this->apiData()->getAccessToken() );
		}
		return $this->accessTokenObj;
	}

	/**
	 * 获取sign对象
	 * @return ApiRequest\ApiSign sign对象
	 */
	public function sign():ApiRequest\ApiSign {
		if( ! isset( $this->signObj ) ){
			$this->signObj = new ApiRequest\ApiSign( $this );
		}
		return $this->signObj;
	}

	/**
	 * 获取auth对象
	 * @return ApiRequest\ApiAuth auth对象
	 */
	public function auth():ApiRequest\ApiAuth {
		if( ! isset( $this->authObj ) ){
			$this->authObj = new ApiRequest\ApiAuth( $this );
		}
		return $this->authObj;
	}

	/**
	 * 获取api响应对象
	 * @return ApiResponse api响应对象
	 */
	public function apiResponse():ApiResponse {
		if( ! isset( $this->apiResponse ) ){
			$this->apiResponse = new ApiResponse();
		}
		return $this->apiResponse;
	}

}
